<template>
	<view class="app">
		<mescroll-body
			ref="mescrollRef" 
			@init="mescrollInit" 
			:top="10" 
			:up="upOption" 
			@up="loadData" 
			@down="refreshList" 
		>
			<view v-for="(item, index) in list"  :key="index">
				<vew  class="item column"  v-if="item.status===1">
					<view class="i-header row b-b">
						<text class="title fill">{{ item.courseName  }}</text>
					</view>
					<view class="i-header row b-b">
						<text class="title fill">上课日期</text>
						<text  class="state gray" v-if="item.courseDate"> {{ item.courseDate.replace(/,/g, " 至 ")   }}</text>
					</view>
					<view class="i-header row b-b">
						<text class="title fill">上课周期</text>
						<text  class="state gray" > {{ item.courseWeek  }}</text>
					</view>
					<view class="i-header row b-b">
						<text class="title fill">上课时间</text>
						<text  class="state gray" v-if="item.courseTime"> {{ item.courseTime.replace(/,/g, " 至 ")   }}</text>
					</view>
					<view class="i-header row b-b">
						<text class="title fill">上课地点</text>
						<text  class="state gray" > {{ item.courseRoom  }}</text>
					</view>
					<view class="i-header row b-b">
						<text class="title fill">上课讲师</text>
						<text  class="state gray" > {{ item.username  }}</text>
					</view>
					<view class="i-header row b-b">
						<text class="title fill">课程成绩</text>
						<text  class="state gray" v-if="item.mark"> {{ item.mark  }}</text>
					</view>
					<view class="btn-group row" >
						<view class="btn center round" @click="navTo('/pages/product/detail?id='+item.courseId)">
							<text>查看更多</text>
						</view>
					</view>	
				</vew>
			</view>
		<view  class="mix-nodata center">
			<text>————我是有底线的————</text>
		</view>
		</mescroll-body>
		<mix-loading v-if="isLoading" :mask="true"></mix-loading>
	</view>
</template>

<script>
	import MescrollBody from "@/components/mescroll-uni/mescroll-body.vue"
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	import OrderMixin from './mixin/order.js'
	export default {
		components: {
			MescrollBody
		},
		mixins: [MescrollMixin, OrderMixin],
		data() {
			return {
				curPage: 'orderList',
				navCounts: [], //订单数量
				navs: [{name: '全部'}, {name: '已报名'}, {name: '退课中'}, {name: '已退课'}, {name: '已拒绝'}],
				navCurrent: 0, //当前tab
				upOption:{
					page: {
					 	num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
					 	size: 10 // 每页数据的数量
					},
					noMoreSize: 3, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
				},
				modalText: '', //确认对话框内容
				list: [] ,//订单列表
				status:2,
				reject:2
			}
		},
		computed: {
			orderCount(){
				return this.$store.state.orderCount;
			}
		},
		watch: {
			orderCount(){
				this.list = this.orderCount;
			}
		},
		onLoad(options) {
			this.list = this.orderCount;
		},
		onShow(){
			if(this.loaded){
				this.refreshList(false);
			}
		},
		methods: {
			async loadData(e){
				// this.$store.dispatch('getOrderCount');
				setTimeout(()=>{
					this.isLoading=false
				}, 2000)
				
				// this.mescroll && this.mescroll.removeEmpty();
				// const sendData = {
				// 	offset: (e.num - 1) * e.size,
				// 	limit: e.size,
				// }
				// if(e.num === 1){
				// 	//第一页清空数据重载
				// 	this.loaded && curList.forEach(item=> {item.loaded = true})
				// 		uni.pageScrollTo({
				// 			scrollTop: 0,
				// 			duration: 0
				// 		})
					
				// } 
				this.mescroll.endSuccess(); //结束加载状态
			},
			//刷新列表
			refreshList(showLoading){
				this.mescroll && this.mescroll.resetUpScroll(false)
				if(showLoading !== false){
					this.isLoading = true;
				}
				this.$store.dispatch('getOrderCount');
				// this.isLoading=false
				console.log("refreshList");
			},
			mescrollInit(mescroll){
				this.mescroll = mescroll;
				setTimeout(()=>{
					this.refreshList();
				}, 10)
			},
			//tab切换
			onNavBarChange(current){
				if(this.navCurrent === current){
					return;
				}
				this.navCurrent = current;
				console.log(current);
				// this.refreshList();
				if(current===1){
					this.status = 1;
					this.reject = 0;
				}else if(current===2){
					this.status = 0;
					this.reject = 0;
				}else if(current===3){
					this.status = -1;
					this.reject = 0;
				}else if(current===4){
					this.status = 1;
					this.reject=1;
				}else{
					this.status = 2;
					this.reject = 2;
				}
			},
		}
	}
</script>

<style>
	page{
		background-color: #f7f7f7;
	}
</style>
<style scoped lang="scss">
	.app{
		
	}
	.item{
		width: 710rpx;
		padding-bottom: 24rpx;
		margin-top: 20rpx;
		margin-left: 20rpx;
		background-color: #fff;
		border-radius: 12rpx;
	}
	.b-b:after{
		left: 4rpx;
		right: 4rpx;
		border-color: #e5e5e5;
	}
	.i-header{
		height: 80rpx;
		padding: 0 24rpx;
		margin-bottom: 24rpx;
		
		.time{
			font-size: 26rpx;
			color: #999;
		}
		.state{
			font-size: 30rpx;
			color: $base-color;
			
			&.gray{
				color: #999;
			}
		}
	}
	.scroll-view{
		width: 100%;
		height: 150rpx;
		
		.goods-list{
			display: flex;
			
			&::before, &::after{
				content: '';
				width: 20rpx;
				height: 130rpx;
				flex-shrink: 0;
			}
			&::after{
				width: 10rpx;
			}
			.image-wrapper{
				flex-shrink: 0;
				width: 130rpx;
				height: 130rpx;
				margin-right: 16rpx;
				border-radius: 4rpx;
				overflow: hidden;
			}
			image{
				width: 100%;
				height: 100%;
			}
		}
	}
	.goods-wrap{
		padding: 0 20rpx;
		
		.image-wrapper{
			width: 130rpx;
			height: 130rpx;
			border-radius: 4rpx;
			overflow: hidden;
			
			image{
				width: 100%;
				height: 100%;
			}
		}
		.right{
			flex: 1;
			padding-left: 20rpx;
			overflow: hidden;
		}
		.title{
			font-size: 26rpx;
			color: #333;
		}
		.attr{
			margin: 16rpx 0 20rpx;
			min-height: 30rpx;
			font-size: 24rpx;
			color: #999;
		}
		.r-b{
			display: flex;
			height: 30rpx;
		}
		.price{
			font-size: 28rpx;
			color: #333;
			font-weight: normal;
		}
		.number{
			margin-left: 16rpx;
			font-size: 26rpx;
			color: #999;
		}
	}
	.price-wrap{
		display: flex;
		justify-content: flex-end;
		padding: 16rpx 24rpx 30rpx;
		font-size: 26rpx;
		color: #333;
		
		.price{
			font-size: 30rpx;
			font-weight: 700;
		}
	}
	.btn-group{
		justify-content: flex-end;
		padding-right: 16rpx;
		
		.btn{
			width: 150rpx;
			height: 60rpx;
			margin-left: 20rpx;
			font-size: 24rpx;
			color: #fff;
			background-color: $base-color;
			border-radius: 100rpx;
		}
		.round{
			background-color: #fff;
			color: #333;
		}
	}
	.mix-nodata{
		height: 52rpx;
		font-size: 26rpx;
		color: #999;
	}
	.teacher{
		margin-bottom: 1rpx;
	}
	.teacherName{
		background-color: #e5e5e5;
		color: #969696;
		margin-right:15rpx;
		font-size: 16rpx;
		margin-top: 10rpx;
	}
</style>
